package Imp.lisener;


import Imp.clients.openFeignThird;
import Imp.mappers.usemapper;
import entity.Order;
import lombok.extern.slf4j.Slf4j;
import org.apache.seata.spring.annotation.GlobalTransactional;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Slf4j
@Component
public class OrderDelay {
    @Autowired
    openFeignThird openFeignThird;

    @Autowired
    usemapper usemapper;
    @RabbitListener(bindings = @QueueBinding(value = @Queue(name = "delay.queue"),
            exchange = @Exchange(name = "delay.direct", delayed = "true"),
            key = {"delay"}))
    public void delay(int orderid) {
        log.info("Delay Message Received:{}",orderid);
        Order order = usemapper.getOrder(orderid);
        if(order.getCheck_pay() != 1) {
            log.info("订单未支付，恢复库存 orderID : {}",order);
            int itemid = order.getItemid();
            int number = order.getNumber();
            try {
                openFeignThird.getFallbackStock(itemid,number);
            }catch (Exception e){
                e.printStackTrace();
            }

        }else {
            log.info("已支付 orderID : {}",orderid);
        }

    }
}
